//<template>
  <div>
      <table border="1">
         <tr>
        <td>商品名称</td>
         <td>价格</td>
         <td>数量 </td>
         <td>小计</td>
         </tr>
         
         <tr v-for="i in name" :key="i">
            <td>{{i.a}}</td>
            <td>{{i.c}}</td>
            <td>{{i.b}}</td>
            <td>{{i.d}}</td>
            
         </tr>
         <tr>
             总计:{{main}}
            <select v-model="ma" @click="all()">
             <option  v-for="i in passa" :key="i">{{i.name}}</option>
         </select>
         </tr>
         
 
      </table>
        实际付款金额：{{this.mm}}
  </div>
</template>

<script>
import axios from "axios"
export default {
    name:'GouWu',
    data(){
        return{
            // 展示商品
            name:"",
            // 总价钱
            main:"",
            // 优惠卷展示
            passa:"",
            // 实付价格
            mm:"",
            // 优惠卷名
            ma:""
        }
    },
    methods:{
        ajj(){
            if(sessionStorage.getItem("人工智能宝典")){
                if(sessionStorage.getItem("物联网白皮书")){
                    this.name=[{"a":"人工智能宝典","b":sessionStorage.getItem("人工智能宝典"),"c":"20","d":parseInt(sessionStorage.getItem("人工智能宝典"))*parseInt(20)},{"a":"物联网白皮书","b":sessionStorage.getItem("物联网白皮书"),"c":"10","d":parseInt(sessionStorage.getItem("物联网白皮书"))*parseInt(10)}]
                    this.main=parseInt(this.name[1]["d"])+parseInt(this.name[0]["d"])}else{
                    this.name=[{"a":"人工智能宝典","b":sessionStorage.getItem("人工智能宝典"),"c":"20","d":parseInt(sessionStorage.getItem("人工智能宝典"))*parseInt(20)}]
                    this.main=parseInt(this.name[0]["d"])
                }
            }else{
                if(sessionStorage.getItem("物联网白皮书")){
                    this.name=[{"a":"物联网白皮书","b":sessionStorage.getItem("物联网白皮书"),"c":"10","d":parseInt(sessionStorage.getItem("物联网白皮书"))*parseInt(10)}]
                    this.main=parseInt(this.name[0]["d"])
                }
            }
            axios({
                url:"http://127.0.0.1:8000/app01/favourable",
                method:"get",        
            }).then(res=>{
                this.passa=res.data.data
            })
            
        },
        all(){
                sessionStorage.setItem("使用优惠卷",this.ma)
                if(parseInt(this.main)>10){
                    if(sessionStorage.getItem("使用优惠卷")=="满二元减十元")
                    {this.mm=parseInt(this.main)-10}
                    if(sessionStorage.getItem("使用优惠卷")=="满十元减五元")
                    {this.mm=parseInt(this.main)-5}}
                if(this.main=="10"){
                    if(sessionStorage.getItem("使用优惠卷")=="满十元减五元")
                    {this.mm=parseInt(this.main)-5}
                    else{
                        this.mm=this.main
                    }}
                    
                }

    },
    created() {
        this.ajj()
        
    },

}
</script>

<style>

</style>